var level = 2;
var trade_name = ['trade_1th','trade_2th','trade_3th'];

function change(obj){
	var selId = obj.find('option:selected').val();
	var next_sel ,
	    html,
		list ;
	$.ajax({
		url : trade_url,
		data :{trade_id : selId,level:level},
		dataType:'json',
		async : false,
		type :'post',
		success:function(data){
			if(data.code==200){
				list = data.trade_list;
			}else{
				list = null;
			}
		}
	})

	//下面有数据
	if(list){

		//下一个有没有选择框
		if(obj.next().is('select')){
			next_sel =	obj.next();
			$.each(list,function(i,trade){
				// console.log(trade);
				html += '<option value="'+trade.trade_id+'">'+trade.name+'</option>';
			})
			next_sel.html(html);
			next_sel.bind('change',function(){
				change($(this));
			});
			next_sel.trigger('change');
		}else{

			//下一个不是选择框
			next_sel = document.createElement('select');
			$.each(list,function(i,trade){
				var option = new Option(trade.name,trade.trade_id);
				next_sel.add(option,undefined);
			})
			obj.after($(next_sel));
			$(next_sel).bind('change',function(){
				change($(this));
			})
			$(next_sel).trigger('change');
			
		}
	}else{
		obj.nextAll('select').remove();
	}
}
$('select#'+[name=trade_name[0]]).change(function(){
		change($(this));	
})